{% extends 'layout.html' %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">编辑资产组信息</h3>

                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
                                class="fa fa-chevron-up"></i>
                        </button>
                        <div class="btn-group">
                            <button type="button" class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-wrench"></i></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                            </ul>
                        </div>
                        <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
                        </button>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="col-sm-10">
                        <form id="group_form" method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-md-2">组名<span class="text-red">*</span>：</label>
                                <div class="col-md-10">
                                    {{ assetgroup_form.name }}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">主机<span class="text-red">*</span>：</label>
                                <div class="col-sm-4">
                                    <select id="asset_no_select" name="assets" class="form-control m-b" size="12" multiple>
                                        {% for asset in asset_no_select %}
                                            <option value="{{ asset.id }}">
                                                {{ asset.hostname }} - {{ asset.ip }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-sm-1">
                                    <div class="btn-group" style="margin-top: 50px;">
                                        <button type="button" class="btn btn-white" style="margin-bottom: 5px;"
                                                onclick="move('asset_no_select', 'asset_select')"><i
                                                class="fa fa-chevron-right"></i></button>
                                        <button type="button" class="btn btn-white"
                                                onclick="move('asset_select', 'asset_no_select')"><i
                                                class="fa fa-chevron-left"></i></button>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div>
                                        <select id="asset_select" name="asset_select" class="form-control m-b" size="12"
                                                multiple>
                                            {% for asset in asset_select %}
                                                <option value="{{ asset.id }}">
                                                    {{ asset.hostname }} - {{ asset.ip }}
                                                </option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                </div>

                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">备注：</label>
                                <div class="col-md-10">
                                    {{ assetgroup_form.comment }}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button id="submit_button" class="btn btn-default" type="submit">保存</button>
                                    <a href="javascript:history.go(-1)" class="btn btn-white">取消</a>
                                    <!--<button class="btn btn-white" type="submit">取消</button>-->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block self_footer_js %}
    <script>
        //提交表单数据之前，先选中右侧
        $(document).ready(function () {
            $("#submit_button").click(function () {
                $('#asset_select option').each(function () {
                    $(this).prop('selected', true)
                })
            })
        });

        $('#group_form').validator({
            timely: 2,
            theme: "yellow_right_effect",
            stopOnError: true,
            fields: {
                "name": {
                    rule: "required",
                    tip: "组名",
                    ok: ""
                }
            },
            valid: function (form) {
                form.submit();
            }
        });
    </script>
{% endblock %}